package com.zj.core.ui

import android.content.Context
import android.graphics.Color
import android.support.constraint.ConstraintLayout
import android.support.constraint.ConstraintLayout.LayoutParams.PARENT_ID
import android.support.v7.widget.RecyclerView
import android.view.Gravity
import android.view.View
import android.view.ViewManager
import android.widget.LinearLayout
import android.widget.TextView
import com.zj.core.R
import org.jetbrains.anko.*
import org.jetbrains.anko.constraint.layout.constraintLayout
import org.jetbrains.anko.custom.ankoView

class DialogTemplateUi(context: Context,listener: View.OnClickListener){
    private var mContext: Context = context
    private var mClickListener:View.OnClickListener=listener
    var view_root:LinearLayout?=null
    var common_dialog_top_rl:ConstraintLayout?=null
    var common_dialog_title_tv: TextView?=null
    var common_dialog_all_check:TextView?=null
    var template_list_rv:RecyclerView?=null
    var common_dialog_bottom_ll:LinearLayout?=null
    var common_dialog_cancel_tv:TextView?=null
    var common_dialog_vertical_line: View?=null
    var common_dialog_confirm_tv:TextView?=null

    init {
        view_root=mContext.linearLayout {
            backgroundDrawable=mContext.resources.getDrawable(R.drawable.popup_dialog_bg)
            orientation=LinearLayout.VERTICAL

            common_dialog_top_rl=constraintLayout {
                id=R.id.common_dialog_top_rl

                common_dialog_title_tv=textView {
                    text="模板列表"
                    textSize=dip(12).toFloat()
                    textColor=Color.parseColor("#555555")
                    id=R.id.common_dialog_title_tv
                    gravity=Gravity.CENTER_HORIZONTAL
                }.lparams(width= wrapContent,height = wrapContent){
                    topToTop=PARENT_ID
                    bottomToBottom=PARENT_ID
                    leftToLeft=PARENT_ID
                    rightToRight=PARENT_ID
                    topMargin=dip(15)
                    bottomMargin=dip(15)
                }

                common_dialog_all_check=textView{
                    id=R.id.common_dialog_all_check
                    gravity=Gravity.CENTER
                    text="全选"
                    textSize=dip(12).toFloat()
                    setOnClickListener(mClickListener)
                    textColor=Color.parseColor("#0679FE")
                }.lparams(width=wrapContent,height = 0){
                    topToTop=PARENT_ID
                    bottomToBottom=PARENT_ID
                    rightToRight=PARENT_ID
                    topMargin=dip(15)
                    bottomMargin=dip(15)
                    rightPadding=dip(15)
                }
            }.lparams(width= matchParent,height = wrapContent){
                gravity=Gravity.CENTER_VERTICAL
            }

            view {
                backgroundColor=Color.parseColor("#F5F5F5")
            }.lparams(width= matchParent,height = dip(1))

            template_list_rv=recyclerview{
                id=R.id.template_list_rv
            }.lparams(width= matchParent,height = 0){
                weight=1F
            }

            view {
                backgroundColor=Color.parseColor("#F5F5F5")
            }.lparams(width= matchParent,height = dip(1))

            common_dialog_bottom_ll=linearLayout {
                id=R.id.common_dialog_bottom_ll
                orientation=LinearLayout.HORIZONTAL

                common_dialog_cancel_tv=textView {
                    id=R.id.common_dialog_cancel_tv
                    isClickable=true
                    gravity=Gravity.CENTER
                    text="取消"
                    setOnClickListener(mClickListener)
                    textSize=dip(12).toFloat()
                    textColor=Color.parseColor("#0679FE")
                }.lparams(width=0,height = matchParent){
                    weight=1F
                }

                common_dialog_vertical_line=view {
                    id=R.id.common_dialog_vertical_line
                    backgroundColor=Color.parseColor("#F5F5F5")
                }.lparams(width=dip(1),height = matchParent)

                common_dialog_confirm_tv=textView {
                    id=R.id.common_dialog_confirm_tv
                    isClickable=true
                    gravity=Gravity.CENTER
                    text="确定"
                    setOnClickListener(mClickListener)
                    textSize=dip(12).toFloat()
                    textColor=Color.parseColor("#0679FE")
                }.lparams(width=0,height = matchParent){
                    weight=1F
                }
            }.lparams(width= matchParent,height = dip(50))
        }
    }

    inline fun ViewManager.recyclerview(theme: Int = 0, init:RecyclerView.() -> Unit) :RecyclerView {
        return ankoView({ RecyclerView(it) }, theme, init)
    }
}